package mid

import "workspace/node"

func RemoveNthFromEnd(head *node.ListNode, n int) *node.ListNode {
	dummy := &node.ListNode{Val: 0, Next: head}
	first, second := head, dummy
	for i := 0; i < n; i++ {
		first = first.Next
	}
	for first != nil {
		first = first.Next
		second = second.Next
	}
	second.Next = second.Next.Next
	return dummy.Next
}
